package day12;
//volatile禁止指令重排序
public
class Demo3 {
    static int a, b, c, d;

    public static
    void main(String[] args) throws InterruptedException {
        int i = 0;//计数
        while (true) {
            i++;
            a = b = c = d = 0;//每循环一次重置a,b,c,d的值
            Thread t1 = new Thread(() -> {
                a = 1;
                c = b;
            });
            Thread t2 = new Thread(() -> {
                b = 1;
                d = a;
            });
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            if (c == 0 && d == 0) {
                System.out.println("第" + i + "次循环，出现重排序");
                break;
            } else {
                System.out.println(i );
            }
        }
    }
}
